package queue.priority;

import java.util.Comparator;

public abstract class AbstractPriorityQueue<K, V> implements PriorityQueue<K, V> {
	protected static class PQEntry<K, V> implements Entry<K, V>{
		private K key;
		private V value;
		
		public PQEntry(K key, V value) {
			this.key = key;
			this.value = value;
		}
		
		public void setKey(K key) {
			this.key = key;
		}

		public void setValue(V value) {
			this.value = value;
		}

		@Override
		public K getKey() {
			return key;
		}

		@Override
		public V getValue() {
			return value;
		}
	}
	
	public static class DefaultComparator<E> implements Comparator<E> {
		@Override
		public int compare(E o1, E o2) throws ClassCastException {
			return ((Comparable<E>)o1).compareTo(o2);
		}
	}
	
	private Comparator<K> comp;

	public AbstractPriorityQueue(Comparator<K> comp) {
		this.comp = comp;
	}
	
	public AbstractPriorityQueue() {
		this(new DefaultComparator<K>());
	}
	
	protected int compare(Entry<K, V> a, Entry<K, V> b) {
		return comp.compare(a.getKey(), b.getKey());
	}
	
	public boolean isEmpty() {
		return size() == 0;
	}
}
